<?php
/* OpenBIBLIO -- A library administration web interface
 * Copyright (C) 2002-2005 Fr&eacute;d&eacute;ric Descamps <lefred@tiscali.be>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

if($_GET['id']) $id=$_GET['id'];
else $id=$_POST['id'];

if(!$id)
{
        $requete = "select * from etats order by value, etat;";
        if(!($resultat = biblio_db_query($requete)))
        { print "PROBLEME : " .biblio_db_error(); }
        else 
        {
                echo "<CENTER><H3>";
		echo _("Modifier un &eacute;tat de livre");
		echo "</H3>";
                echo "<TABLE><th>";
		echo _("Etat");
		echo "</th><th>";
		echo _("Action");
		echo "</TD>";
        
                while ($row = biblio_db_fetch_array($resultat)) 
	        {      
                        $etat_id = $row['id'];           
                        $etat_nom =  $row['etat'];
                        echo "<TR><TD>$etat_nom</TD><TD align=right><A href=\"admin.php?action=mod&type=status&id=$etat_id\"><IMG SRC=\"images/wh_r_arr.gif\" ALT=\"";
			echo _("changer"); 
			echo "\" border=0></A></TD>";            
                }
                echo "</TABLE></CENTER>";
        }
}
else
{
    if ($_POST['sw']!=1)
    {
 
       $requete = "select * from etats where id=$id";
        if(!($resultat = biblio_db_query($requete)))
        { print "PROBLEME : " .biblio_db_error(); }
        else 
        {
                while ($row = biblio_db_fetch_array($resultat)) 
	        {      
                        $etat_id = $row['id'];           
                        $etat_nom =  $row['etat'];      
			$etat_value = $row['value'];
                }
         }
        ?>
        <CENTER><H3>
	<?php echo _("Modifier l'&eacute;tat"); ?>
	</H3>
        <I>
	<?php echo _("Tous les livres ayant cet &eacute;tat seront modifi&eacute;s en cons&eacute;quence..."); ?>
	</I><BR><BR>
        <FORM action=admin.php METHOD=POST>
        <TABLE BORDER=0>
        <TR>
        <TD>
	<?php echo _("Etat"); ?> 
	:</TD><TD><INPUT TYPE="text" NAME="etat" size = 20 value="<?php echo $etat_nom; ?>"></TD>
	</tr>
        <tr>
	<td>
	<?php echo _("Echelle de valeur"); ?>
	:</td><td>
	<span style="background-color: #ff0000"><input type=radio name=etat_value value=0 <?php if($etat_value==0) echo "checked"; ?>>0</span>
	<span style="background-color: #fd1006"><input type=radio name=etat_value value=1 <?php if($etat_value==1) echo "checked"; ?>>1</span>
	<span style="background-color: #fe6b10"><input type=radio name=etat_value value=2 <?php if($etat_value==2) echo "checked"; ?>>2</span>
	<span style="background-color: #fe7a12"><input type=radio name=etat_value value=3 <?php if($etat_value==3) echo "checked"; ?>>3</span>
	<span style="background-color: #fed01d"><input type=radio name=etat_value value=4 <?php if($etat_value==4) echo "checked"; ?>>4</span>
	<span style="background-color: #feea20"><input type=radio name=etat_value value=5 <?php if($etat_value==5) echo "checked"; ?>>5</span>
	<span style="background-color: #e5fe26"><input type=radio name=etat_value value=6 <?php if($etat_value==6) echo "checked"; ?>>6</span>
	<span style="background-color: #b4fe2e"><input type=radio name=etat_value value=7 <?php if($etat_value==7) echo "checked"; ?>>7</span>
	<span style="background-color: #7fff36"><input type=radio name=etat_value value=8 <?php if($etat_value==8) echo "checked"; ?>>8</span>
	<span style="background-color: #33ff00"><input type=radio name=etat_value value=9 <?php if($etat_value==9) echo "checked"; ?>>9</span>
	<span style="background-color: #65ff3b"><input type=radio name=etat_value value=10 <?php if($etat_value==10) echo "checked"; ?>>10</span>
        </TABLE><BR>
        <INPUT TYPE="hidden" NAME="user" value="<?php echo $user; ?>">
        <INPUT TYPE="hidden" NAME="action" value="<?php echo $action; ?>">
        <INPUT TYPE="hidden" NAME="type" value="<?php echo $type; ?>">
        <INPUT TYPE="hidden" NAME="sw" value="1">
        <INPUT TYPE="hidden" NAME="id" value="<?php echo $id; ?>">        
        <input type="Submit" value="
	<?php echo _("Enregistrer"); ?>
	">
        </FORM>
        </CENTER>
        <?php
    }   
    else
    {
      $requete = "update etats set etat='${_POST['etat']}', value=${_POST['etat_value']} where id=$id";
      if(!($resultat = biblio_db_query($requete)))
      { echo "PROBLEME : " . $requete . "<br>" . biblio_db_error(); exit;}  
      put_log(3,$requete,$user);
      echo "<CENTER><BR>";
      echo _("L'&eacute;tat a &eacute;t&eacute; modifi&eacute; comme");
      echo ": <b>${_POST['etat']}</b>.<br></center>";
    } 
}
?>
<br><br>
<div>
<span id=left-text>
<A HREF="admin.php?menu=1">
<?php echo _("retour menu administration"); ?>
</A><BR>
<A HREF="index.php">
<?php echo _("retour menu principal"); ?>
</A></span>
</div>
<br>
